package controll;

import java.io.IOException;
import com.guava.framework.Controller;

import pojo.nutz.*;

/**
 * IndexController
 */
public class RegistController extends Controller {
	public void index() throws IOException {
		render("regist.html");
	}

	public void login() throws IOException {
		render("login.html");
	}

	public void logincheck() throws IOException {
		String tel = getPara("tel");
		String password = getPara("password1");
		User user = new User_model(getDao()).getBytel(tel);
		if (user != null) {
			if (user.password.equals(password)) {
				setSessionAttr("userid", user.id);
				renderText("登陆成功");
				// +getSessionAttr("userid")
			} else {
				renderText("密码不正确");
			}
		} else {
			renderText("该用户不存在");
		}
	}
	
	public void add() throws IOException {
		String tel = getPara("tel");
		User_model user_model = new User_model(getDao());
		User user = user_model.getBytel(tel);
		if (user != null) {
			setAttr("message", "该用户已经存在 请重新注册");
		} else {

			User user2 = new User();
			user2.tel = tel;
			user2.password = getPara("password");
			getDao().insert(user2);
			setAttr("message", "注册成功");
		}
		// setAttr("tel",tel);
		render("registadd.html");
	}
}
